package controller;


import biz.DeptService;
import biz.impl.DeptServiceImpl;
import entity.Dept;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/update_show")
public class DeptUpdateShowController extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //0. 先实例化一个业务层对象，用来调用单查方法
        DeptService ds=new DeptServiceImpl();

        //1. 设置编码方式
        resp.setCharacterEncoding("UTF-8");
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=utf-8");

        System.out.println("测试");
        //2. 接收表单传过来的值
        int deptId=Integer.parseInt(req.getParameter("dId"));
        System.out.println("id-->"+deptId);

        //3. 调用业务实现层的单查方法,得到要修改的对象
        Dept d=ds.getOneById(deptId);
        System.out.println(d);
        //4. 把要修改的对象装到req里
        req.setAttribute("d",d);

        //5. 转发
        req.getRequestDispatcher("dept_update_show.jsp").forward(req,resp);

    }
}
